<h2 class="page-header well">
    <a class="h2 text-primitive" href="{{group_url(project.group)}}">{{project.group.display_name}}</a>
    » <a class="h2 text-primitive" href="{{project_url(project)}}">{{project.display_name}}</a>
    » {% include "squad/_unfinished_build.jinja2" %} <a class="h2 text-primary" href="{{build_url(build)}}">{{ _('Build %s') % build.version }}</a>
    {% with status=build.status %}
        {% if status.has_tests %}
            » {% include "squad/_test_results_summary.jinja2" %}
        {% endif %}
    {% endwith %}
    {% if build.is_release %}
    <i class="fa fa-tag"></i>
    {% endif %}
</h2>

{% if build.patch_source and build.patch_id %}
<div class="well">
    <div class="row">
      <div id="patchsource_text" class="col-md-11">
      {% if build.patch_url %}
        {{ _('Build was started by') }} <a href="{{ build.patch_url }}">{{ build.patch_url }}</a>.
      {% else %}
        {{ _('Build was started by') }} {{ _('change') }} {{ build.patch_id }} {{ _('from') }} {{ build.patch_source.url }}.
      {% endif %}
      </div>
    </div>
</div>
{% endif %}

{% if not build.status.finished %}
{% with reasons=build.finished.1 %}
{% if reasons %}
<div class="well">
  <div class="row">
    <div class="col-md-11">
      <p>
      {{ _('This build is not considered finished yet for the following reasons:') }}
      </p>
      <ul>
          {% for reason in reasons %}
          <li>{{reason}}</li>
          {% endfor %}
      </ul>
      <p>
      {{ _('Being unfinished, this build will not trigger email notifications.') }}
      </p>
    </div>
  </div>
</div>
{% endif %}
{% endwith %}
{% endif %}

{% if project.can_submit_testjobs(user) %}
<div class="highlight-row">
  <div class="alert alert-info annotation-alert">
    <div class="row">
      <div id="annotation_text" class="col-md-11 annotation-text-col {% if not build.annotation %}hidden{% endif %}">
        {% if build.annotation %}
        <strong>{{ _('Annotation:') }}</strong>
        {{ build.annotation.description }}
        {% endif %}
      </div>
      <div class="col-md-1">
        <a href="#" data-toggle="modal" data-target="#annotation_modal">
          <button id="annotation_button" type="submit" class="btn btn-primary">{% if build.annotation %}{{ _('Update') }}{% else %}{{ _('Add annotation') }}{% endif %}</button>
        </a>
      </div>
    </div>
  </div>
</div>
<div class="highlight-row">
  <div class="alert alert-info annotation-alert">
    <div class="row">
      <div id="release_text" class="col-md-11 release-text-col {% if not build.is_release %}hidden{% endif %}">
        {% if build.is_release %}
        <i class="fa fa-tag"></i>
        {% endif %}
        {% if build.release_label %}
        <strong>{{ _('Release:') }}</strong>
        {{ build.release_label | safe }}
        {% endif %}
      </div>
      <div class="col-md-1">
        <a href="#" data-toggle="modal" data-target="#release_modal">
          <button id="release_button" type="submit" class="btn btn-primary">{% if build.is_release %}{{ _('Update') }}{% else %}{{ _('Mark release') }}{% endif %}</button>
        </a>
      </div>
    </div>
  </div>
</div>
{% endif %}

<ul class="page-header nav nav-pills build-nav-header">
    {% with url_name=request.resolver_match.url_name %}

    <li role="presentation" {% if url_name == 'build' %}class="active"{% endif %}>
        <a href="{{build_url(build)}}">
            {{ _('Summary') }}
        </a>
    </li>
    <li role="presentation" {% if url_name == 'tests' or url_name == 'test_history' %}class="active"{% endif %}>
        <a href="{{build_section_url(build, 'tests')}}">
            {{ _('Tests') }}
        </a>
    </li>
    <li role="presentation" {% if url_name == 'build_metrics' %}class="active"{% endif %}>
        <a href="{{build_section_url(build, 'build_metrics')}}">
            {{ _('Metrics') }}
        </a>
    </li>
    <li role="presentation" {% if url_name == 'build_metadata' %}class="active"{% endif %}>
        <a href="{{build_section_url(build, 'build_metadata')}}">
        {{ _('Metadata') }}
        </a>
    </li>
    {% if build.test_jobs.count() %}
    <li role="presentation" {% if url_name == 'testjobs' %}class="active"{% endif %}>
        <a href="{{build_section_url(build, 'testjobs')}}">
            {{ _('Test jobs') }}
        {% for i in build|filter_jobs %}
        <span class="badge badge-{{ i.0 }}" data-toggle="tooltip" data-placement="top" title="{{ i.0 }}">{{ i.1 }}</span>
        {% endfor %}
        </a>
    </li>
    {% endif %}
    {% if project.writable_by(user) and build.callbacks.count() %}
    <li role="presentation" {% if url_name == 'build_callbacks' %}class="active"{% endif %}>
        <a href="{{build_section_url(build, 'build_callbacks')}}">
            {{ _('Callbacks') }}
        </a>
    </li>
    {% endif %}
    {% if project.writable_by(user) %}
    <li role="presentation" {% if url_name == 'build_settings' %}class="active"{% endif %}>
        <a href="{{build_section_url(build, 'build_settings')}}">
            {{ _('Settings') }}
        </a>
    </li>
    {% endif %}

    {% endwith %}
    <a href="{{next_build_url(build)}}" class="btn btn-default pull-right" data-toggle="tooltip" data-placement="bottom" title="Next Build"><i class='fa fa-chevron-right'>&nbsp;</i></a>
    <a href="{{back_to_latest_build_url(build)}}" class="btn btn-default pull-right" data-toggle="tooltip" data-placement="bottom" title="Latest Build"><i class='fa fa-arrow-circle-up '>&nbsp;</i></a>
    <a href="{{previous_build_url(build)}}" class="btn btn-default pull-right" data-toggle="tooltip" data-placement="bottom" title="Previous Build"><i class='fa fa-chevron-left'>&nbsp;</i></a>

</ul>
<div class="pull-right">
  <a href="/api/builds/{{ build.id }}/">api view of this build</a>
</div>
<!-- Modal HTML -->
<div id="annotation_modal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">{{ _('Build annotation') }}</h4>
      </div>
      <form class="well" id="annotation_form" ng-controller="AnnotationController" ng-submit="updateAnnotation('{{ url("build-detail", args=[build.pk]) }}')" ng-init="{% if build.annotation%}annotation_id={{ build.annotation.id }}{% endif %}">
        <div class="modal-body">
          <div class="row">
            <div class="col-md-3">
              <label for="description">{{ _('Description:') }}</label>
            </div>
            <div class="col-md-9">
              <input name="description" class="annotation-description" ng-model="description" placeholder="Annotation description" ng-init="description='{% if build.annotation %}{{ build.annotation.description }}{% endif %}'" />
            </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ _('Close') }}</button>
        <button class="btn btn-primary">{{ _('Save') }}</button>
      </div>
      </form>
    </div>
  </div>
</div>

<!-- Modal Release window -->
<div id="release_modal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">{{ _('Release') }}</h4>
      </div>
      <form class="well" id="build_release_form" ng-controller="BuildReleaseController" ng-submit="updateRelease('{{ url("build-detail", args=[build.pk]) }}')">
        <div class="modal-body">
          <div class="row">
            <div class="col-md-3">
              <label for="description">{{ _('Is release:') }}</label>
            </div>
            <div class="col-md-9">
              <input type="checkbox" name="is_release" class="build-is-release" ng-model="is_release" ng-init="is_release={{ build.is_release|tojson }}" />
            </div>
          </div>
          <div class="row">
            <div class="col-md-3">
              <label for="description">{{ _('Release label:') }}</label>
            </div>
            <div class="col-md-9">
              <input name="release_label" class="build-release-label" ng-model="release_label" placeholder="Release label" ng-init="release_label='{% if build.release_label %}{{ build.release_label }}{% endif %}'" />
            </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ _('Close') }}</button>
        <button class="btn btn-primary">{{ _('Save') }}</button>
      </div>
      </form>
    </div>
  </div>
</div>
